JavaScript

A5.u.elementcls Method

Syntax

A5.u.element.cls(element,[className[,className[...className]]])

Arguments

elementelementstring

A pointer to a DOM element or the ID of an element.

classNamestring

Class name(s) to set, add, remove or toggle.

Description

Get and/or set the class names of an element.

Discussion

The A5.u.element.cls() method allows for the setting of the class names of an element. By default the passed in class names will overwrite all other class names.

Class names can be added to the current list by using a "+=" prefix.

A prefix of "-=" can be used to remove specific class names.

A prefix of "~=" can be used to toggle specific class names.

On remove and toggle the operation is performed on each class name as opposed to all of the class names. For example, if the class name was "item highlight" and "~=highlight selected" was passed in, the resulting class name would be "item selected".

Zero or more class name operations can be passed in. Each class name operation will be preformed sequentially, allowing for multiple operations in one call. The current class name of the element will be returned by the A5.u.element.cls() method if no class names are passed in. Otherwise the resulting class name after the class name operations are performed will be returned.

Example

// assume "id" is the ID of DIV that wants to be styled
// assume the DIV has an class name of "item highlight"
var cls = A5.u.element.style(id);
// cls = "item highlight"
cls = A5.u.element.cls(id,'+=selected','-=highlight');
// cls = "item selected"
cls = A5.u.element.cls(id,'~=item-alt');
// cls = "item selected item-alt"
cls = A5.u.element.cls(id,'~=item-alt');
// cls = "item selected"